# app.py
import streamlit as st
import pandas as pd
import numpy as np

st.set_page_config(page_title="完整示例应用", layout="wide")

# -----------------------------
# 标题和介绍
# -----------------------------
st.title("完整 Streamlit 示例应用")
st.write("这是一个演示常用组件、交互、文件上传和数据可视化的示例应用。")

# -----------------------------
# 文本输入
# -----------------------------
name = st.text_input("请输入你的名字")
if name:
    st.write(f"你好, {name}!")

# -----------------------------
# 选择框和滑块
# -----------------------------
st.header("选择示例")
option = st.selectbox("选择一个选项", ["选项 A", "选项 B", "选项 C"])
st.write("你选择了:", option)

number = st.slider("选择一个数字", 0, 100, 50)
st.write("滑块数值:", number)

# -----------------------------
# 按钮交互
# -----------------------------
if st.button("点击按钮"):
    st.success("你点击了按钮!")

# -----------------------------
# 文件上传与数据可视化
# -----------------------------
st.header("CSV 文件上传与可视化")
uploaded_file = st.file_uploader("上传 CSV 文件", type="csv")

if uploaded_file is not None:
    df = pd.read_csv(uploaded_file)
    st.write("数据预览:", df.head())
    
    st.subheader("选择列绘制折线图")
    col = st.selectbox("选择列", df.columns)
    st.line_chart(df[col])

# -----------------------------
# 随机数据图表
# -----------------------------
st.header("随机数据图表示例")
df_random = pd.DataFrame(np.random.randn(50, 3), columns=["A", "B", "C"])
st.line_chart(df_random)

# -----------------------------
# 布局示例
# -----------------------------
st.header("布局示例")
col1, col2 = st.columns(2)
with col1:
    st.button("左列按钮")
with col2:
    st.button("右列按钮")

with st.expander("点击展开更多内容"):
    st.write("这里可以放隐藏信息或说明。")

# -----------------------------
# 侧边栏示例
# -----------------------------
st.sidebar.title("侧边栏")
sidebar_option = st.sidebar.selectbox("在侧边栏选择", ["X", "Y", "Z"])
st.sidebar.write("你选择了:", sidebar_option)
